﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Collections;

namespace CompilerPrinciples.SyntaxAnalysis.Bottom_Up_Analysis
{
    public partial class Shift_Reduce_Analysis : BaseSyntax
    {
        #region 构造方法
        public Shift_Reduce_Analysis()
        {
            InitializeComponent();
            ArrayList arrayHeaders = new ArrayList();
            arrayHeaders.Add("步骤");
            arrayHeaders.Add("符号栈");
            arrayHeaders.Add("输入串");
            arrayHeaders.Add("产生式");
            arrayHeaders.Add("动作");
            this.InitDataGridView(arrayHeaders);
        }
        #endregion 

        #region 覆盖父类的方法
        protected override void Add_2DataGridView_Row(
            ArrayList arraySyntaxAnalysisSteps,
            int currentStep)
        {
            CompilerDLL.SyntaxAnalysis.Bottom_Up_Analysis.Model_Shift_Reduce_StepStatus model =
               (CompilerDLL.SyntaxAnalysis.Bottom_Up_Analysis.Model_Shift_Reduce_StepStatus)arraySyntaxAnalysisSteps[currentStep];
            string[] dr ={model.IntStep.ToString(), 
                             model.StrStackProcSymbols ,
                         model.StrCurrentTokens,
                         model.StrCurrentProduction ,
                         model.CurrentAction };

            this.dataGridView1.Rows.Add(dr);
        }

        #endregion 

        #region 构造语法结构
        /// <summary>
        /// 构造语法结构
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnGrammar_Click(object sender, EventArgs e)
        {
            DlgGrammar_BottomUp dlg = new DlgGrammar_BottomUp();
            dlg.ShowDialog();
        }
        #endregion 

        #region 执行语法分析

        /// <summary>
        /// 执行语法分析
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnSyntaxAnalysis_Click(object sender, EventArgs e)
        {
            CompilerDLL.SyntaxAnalysis.Bottom_Up_Analysis.Shift_Reduce_Analysis shift_Reduce =
                new CompilerDLL.SyntaxAnalysis.Bottom_Up_Analysis.Shift_Reduce_Analysis();
            DlgGrammar_BottomUp dlg = new DlgGrammar_BottomUp();
            if (this.rdoYes.Checked)
            {
                this.DoSyntaxParse(shift_Reduce, dlg, "1");
            }
            else
            {
                this.DoSyntaxParse(shift_Reduce, dlg, "0");
            }
           
            this.arraySyntaxAnalysisSteps = shift_Reduce.ArraySyntaxAnalysisSteps;

        }
        #endregion 
    }
}
